﻿using Autofac.Extras.DynamicProxy;
using commonFramwork.Attribute;
using commonFramwork.Interceptor;
using dapper.Repository.Repository;
using Entity.Framework;
using Entity.Framework.InterFace;
using Entity.Framework.Specifications;
using Repository.entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace My.BLL.CacheService
{
    [Intercept(typeof(CacheIntercetor))]
    public class UserCacheService : IUserCacheService
    {
        public readonly IUserRepository _userRepository;


        public UserCacheService()//IUserRepository userRepository
        {
            _userRepository = new Entity.Framework.Respositories.UserRepository(new EntityFrameworkRepositoryContext());
            //  _userRepository = userRepository;
        }

        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <returns></returns>
        [CacheAttribute(commonFramwork.Enum.CacheMethod.get)]
        public IEnumerable<User> GetUserInfo() {
            var users = _userRepository.GetAll();

            _userRepository.Find(new UsersSpecification("ss"));

            return users;
        }

        /// <summary>
        ///存储用户信息
        /// </summary>
        /// <returns></returns>
        [CacheAttribute(commonFramwork.Enum.CacheMethod.remove,"GetUserInfo")]
        public void SetUserInfo(User user)
        {
            _userRepository.Add(user);
            _userRepository.Context.Commit();
        }

    }
}
